import React from 'react'
import ReactDOM from 'react-dom/client'
import { BrowserRouter } from "react-router-dom";
import App from "./app";
import zhCN from 'antd/locale/zh_CN';
import { ConfigProvider } from 'antd';
import store from './store';
import { Provider } from 'react-redux'
// import { userInfo } from '@/store/user/types'
import { getUserInfo } from "@/api/user"


const token = localStorage.getItem("token")
if (token) {
  store.dispatch({ type: 'setToken', value: token })
  getUserInfo().then((e: any) => {
    store.dispatch({ type: 'setUserInfo', value: e })
    store.dispatch({ type: "setShopsOptions", value: e.shops })
  }).catch(() => {
    localStorage.clear()
  }).finally(() => {
    init()
  })

} else {
  init()
}
function init() {
  ReactDOM.createRoot(document.getElementById('root')!).render(
    <React.StrictMode>
      <Provider store={store}>
        <BrowserRouter>
          <ConfigProvider locale={zhCN}>
            <App />
          </ConfigProvider>
        </BrowserRouter>
      </Provider>

    </React.StrictMode>,
  )
}

